import request from "@/utils/request";

const USER_BASE_URL = "/core/tSalesDelivery";

const deliveryOrderMaintenanceApi = {
  /**
   * 获取送货单明细
   * @param parentCode 父级编码
   * @returns 送货单明细
   */
  getDeliveryOrderDetail(parentCode: string) {
    let query = encodeURIComponent(
      JSON.stringify({ pageSize: 1, pageNum: 1, isReturnOrder: 0, code: parentCode })
    );
    return request({
      url: `/core/tSalesOrder/getTSalesOrderList?object=${query}`,
      method: "GET",
    });
  },
  /**
   * 获取送货单列表
   * @param params 送货单列表查询参数
   * @returns 送货单列表
   */
  getDeliveryOrderList(params: DeliveryOrderListQuery) {
    const query = encodeURIComponent(
      JSON.stringify({ statusList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ...params })
    );
    return request({
      url: `${USER_BASE_URL}/getTSalesDeliveryList?object=${query}`,
      method: "GET",
    });
  },
  /**
   * 删除送货单
   * @param id 送货单ID
   * @returns 删除送货单
   */
  deleteDeliveryOrder(id: number) {
    return request({
      url: `${USER_BASE_URL}/delTSalesDelivery`,
      method: "POST",
      data: {
        id,
      },
    });
  },
  /**
   * 删除送货单明细
   * @param id 送货单明细ID
   * @returns 删除送货单明细
   */
  deleteDeliveryOrderDetail(id: number) {
    return request({
      url: `${USER_BASE_URL}/delTSalesDeliveryDetail`,
      method: "POST",
      data: {
        id,
      },
    });
  },
  /**
   * 保存或更新送货单
   * @param data 送货单数据
   * @returns 保存或更新送货单
   */
  saveOrUpdateDeliveryOrder(data: any) {
    return request({
      url: `${USER_BASE_URL}/saveOrUpdateTSalesDelivery`,
      method: "POST",
      data,
    });
  },
};
export default deliveryOrderMaintenanceApi;

/**
 * 送货单明细详情（子级）
 */
export interface DeliveryOrderDetail {
  code: string; //编号
  companyCode: string; //客户编号
  companyName: string; //客户名称
  createName: string; //创建人
  createTime: string; //创建时间
  createUser: number; //创建人ID
  description: string; //描述
  id: number; //ID
  isDelete: number; //是否删除
  modifyName: string; //修改人
  modifyTime: string; //修改时间
  modifyUser: number; //修改人ID
  parentCode: string; //父级编码
  rowRemark: string; //备注
  rowSeq: number; //序号
  shipCode: string; //送货地址
  sortSeq: number; //排序
  sourceCode: string; //来源编码
}

/**
 * 送货单列表详情（父级）
 */
export interface DeliveryOrderList {
  billCode: string; //单据编码
  code: string; //编号
  companyCode: string; //客户编号
  companyName: string; //客户名称
  deliveryDate: string; //送货日期
  deliveryUser: string; //送货人
  driverName: string; //送货人
  genNo: number; //生成单号
  id: number; //ID
  issueDate: string; //单据日期
  otherRef: string; //其他参考
  parentCategory: number; //关联的模块(1=生产计划产生)',
  parentCode: string; //父级编码
  prefix: string; //前缀
  refCode: string; //参考编码
  remark: string; //备注
  salesDeliveryDetailList: DeliveryOrderDetail[]; //送货单明细列表
  salesOrderCodes: string; //销售订单编码列表
  status: number; //状态0=待确认 1=待配送 2=配送中 3=配送完成
  statusList: number[]; //状态列表
  timeScopes: string[]; //时间范围
  otherAttachment?: string; //其他附件
  inspectionReport?: string; //车辆检查单
  signReport?: string; //签收单
  loadingPosition: string;
}

/**
 * 销售订单送货计划明细档
 */
export interface SalesOrderDeliveryPlanDetail {
  id: number; //ID
  code: string; //编号
  parentCode: string; //订单明细编号
  rowSeq: number; //序号
  sortSeq: number; //排序
  productCode: string; //产品编号
  description: string; //描述
  planDate: string; //计划送货日期
  shipCode: string; //送货地址
  qty: number; //数量
  unit: string; //单位
  rowRemark: string; //备注
  status: number; //状态
  deliveryDate: string; //送货日期
  deliveryUser: string; //送货人员
}

/**
 * 送货单列表查询
 */
export interface DeliveryOrderListQuery extends PageQuery {
  statusList?: number[]; //状态列表
  timeScopes?: string[]; //时间范围
  code?: string; //编号
  deliveryUser?: string; //送货人
  status?: number; //状态
}
